﻿#pragma once
#include <QDialog>
#include <QTableWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QLabel>
#include "orders.h"
#include "users.h"
#include "UndoRedo_order.h"

class TicketAdminDialog : public QDialog {
    Q_OBJECT
public:
    explicit TicketAdminDialog(QWidget* parent = nullptr);
private:
    QTableWidget* table;
    QLineEdit* searchEdit;
    QComboBox* statusCombo;
    QComboBox* seatTypeCombo;
    QComboBox* startStationCombo;
    QComboBox* endStationCombo;
    QPushButton* btnSearch;
    QPushButton* btnDelete;
	QPushButton* btnUndo;
	QPushButton* btnRedo;
    QPushButton* btnEditPrice;
    QLabel* orderCountLabel;
    void loadAllOrders(const QString& keyword = "", int statusFilter = -1, const QString& seatType = "", const QString& startStation = "", const QString& endStation = "");
    void showOrderDetail(int row);
    void refundOrder(int row);
    void changeOrder(int row);
    void editPrice(int row);
    void deleteSelectedOrder();
    void editSelectedOrderPrice();
	//下面这些函数是UI相关的初始化函数，因为代码量较大，单独拆分出来
    void setupUI();
    void setupTitleSection(QVBoxLayout* mainLayout);
    void setupFilterSection(QVBoxLayout* mainLayout);
    void setupSearchControls(QVBoxLayout* filterMainLayout);
    void setupStationComboBoxes();
    void setupActionButtons(QVBoxLayout* filterMainLayout);
    void setupTableSection(QVBoxLayout* mainLayout);
    void setupTableColumns();
    void setupStatusSection(QVBoxLayout* mainLayout);
    void setupConnections();
    void setupStyles();

    // 按钮创建辅助方法
    QPushButton* createButton(const QString& text, const QString& color, const QString& hoverColor, int minWidth = 80);
    QPushButton* createActionButton(const QString& text, const QString& color, const QString& hoverColor);

	UndoRedo_order undoRedo; // 撤销重做管理器
};
